//
//  AppDelegate.swift
//  Browser
//
//  Created by 鹏鹏 on 2021/7/3.
//

import UIKit

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {

        TKGestureLockManager.sharedInstance().updateGestureLock(false)
        TKGestureLockManager.sharedInstance().saveGesturesPassword("8416")

        self.window = UIWindow(frame: UIScreen.main.bounds)
        let indexVC = FilelistViewController()
        let naviVC = BaseNavigationController(rootViewController: indexVC)
        self.window?.rootViewController = naviVC

        self.window?.makeKeyAndVisible()

        return true
    }

    func applicationDidBecomeActive(_ application: UIApplication) {
        TKGestureLockManager.sharedInstance()?.showGestureLockWindow()
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        TKGestureLockManager.sharedInstance().showGestureLockWindow()
    }

    func applicationWillResignActive(_ application: UIApplication) {
        TKGestureLockManager.sharedInstance().showGestureLockWindow()
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {

        Logger.printLog(url)

        if url.absoluteString.starts(with: "file:///") {
            if KFileManager.getFileType(withFileName: url.lastPathComponent) == .archive {

                // 解压文件到
                KFileManager.unzipFile(atPath: url.path)
                return true
            } else {
                // 直接拷贝
                KFileManager.moveFileSafe(fromPath: url.path)
                return true
            }
        } else {
            return true
        }
    }

}

